package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.MesEquipmentExamineProject;
import com.hunttown.mes.rpc.exception.ConvertException;
import com.hunttown.mes.rpc.domain.MesEquipmentExamineProjectDTO;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2022-04-19 10:12:56
 */
public class MesEquipmentExamineProjectConverts {

    private static Logger LOG = LoggerFactory.getLogger(MesEquipmentExamineProjectConverts.class);

    public static List<MesEquipmentExamineProjectDTO> convert(List<MesEquipmentExamineProject> mesEquipmentExamineProjectList) {
        if (CollectionUtils.isEmpty(mesEquipmentExamineProjectList)) {
            return Collections.EMPTY_LIST;
        }

        List<MesEquipmentExamineProjectDTO> mesEquipmentExamineProjectListResult = Lists.newArrayList();
        for (MesEquipmentExamineProject mesEquipmentExamineProject : mesEquipmentExamineProjectList) {
            mesEquipmentExamineProjectListResult.add(convert(mesEquipmentExamineProject));
        }
        return mesEquipmentExamineProjectListResult;
    }

    public static MesEquipmentExamineProjectDTO convert(MesEquipmentExamineProject mesEquipmentExamineProject) {
        try {
            return BeanUtils.copy(mesEquipmentExamineProject, MesEquipmentExamineProjectDTO.class);
        } catch (Exception e) {
            LOG.error("MesEquipmentExamineProject到MesEquipmentExamineProjectDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "MesEquipmentExamineProject到MesEquipmentExamineProjectDTO转换失败", e);
        }
    }

    public static MesEquipmentExamineProject convert(MesEquipmentExamineProjectDTO mesEquipmentExamineProjectDTO) {
        try {
            return BeanUtils.copy(mesEquipmentExamineProjectDTO, MesEquipmentExamineProject.class);
        } catch (Exception e) {
            LOG.error("MesEquipmentExamineProjectDTO到MesEquipmentExamineProject转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "MesEquipmentExamineProjectDTO到MesEquipmentExamineProject转换失败", e);
        }
    }
}